function Editor() {
}
Editor.Url = "http://"+ window.location.host.replace("http://","") + "/english/controller/";
Editor.NodeJsServer = 'http://html5.estv.in';
Editor.hostName = Editor.Url;
Editor.service = Editor.Url + "Models-WebCastDomainService.svc/JSON/";
Editor.rows = 10; // so dong hien thi tren luoi
Editor.MessageFind = "Not data";
Editor.successful = "successful";
Editor.fail = "fail";
Editor.logo = "";
Editor.emailActive = "Do you want to send the confirmation email to activate this account?";
Editor.remove = "Are you sure you want to remove this record?";
Editor.KetQuaXoSo = "KQXSWOOINVI";
Editor.countArray = 1010;
Editor.database = "xoso";
Editor.version ="1.0";
Editor.displayName ="Database Xo so";
Editor.size = 1000000;

Editor.isCheckDate = function(dd,mm,yy){
    var bBool = true;
    switch(mm){
        case 1 : case 3 : case 5: case 7: case 8 : case 10 : case 12:{
           break;
        }
        case 2 :{
            if((yy % 4 == 0 && yy %100 !=0) || yy %400 == 0){
                if(dd > 29){
                    alert("Tháng này chỉ có 29 ngày xinh vui lòng chọn lại");
                    bBool = false;
                }
                else{
                    alert("Tháng này chỉ có 28 ngày xinh vui lòng chọn lại");
                    bBool = false;
                }
            }
            break;
        }
        defalut :{
            alert("Tháng này chỉ có 30 ngày xinh vui lòng chọn lại");
            bBool = false;
            break;
        }
    }
    return bBool;
}
/// String

/// String

String.prototype.replaceAll = function (strTarget, strSubString) {
    var strText = this;
    var indexString = strText.indexOf(strTarget);
    while (indexString != -1) {
        strText = strText.replace(strTarget, strSubString);
        indexString = strText.indexOf(strTarget);
    }
    return strText;
}

String.prototype.trim = function () {
    var sString = this;
       if(sString == null || sString == "") {
            return "";
       }
        if (sString.length == undefined) {
            return "";
        }
        while (sString.length != 0) {
            if (sString.substring(0, 1) == ' ') {
                sString = sString.substring(1, sString.length);
            }
            else break;
        }
        while (sString.length != 0) {
            if (sString.substring(sString.length - 1, sString.length) == ' ') {
                sString = sString.substring(0, sString.length - 1);
            }
            else
                break;
        }
        return sString;
}

Array.prototype.contains = function (value) {
    for (var k = 0; k < this.length; k++)
        if (value == this[k])
            return true;
    return false;
}

Array.prototype.searchIndex = function (value) {
    for (var k = 0; k < this.length; k++)
        if (value == this[k])
            return k;
    return -1;
}

Array.prototype.clone = function () {
    var result = new Array();
    for (var k = 0; k < this.length; k++) {
        result.push(this[k]);
    }
    return result;
}

Editor.OpenDatabse = function(){    
    try{
        return window.openDatabase(Editor.database,Editor.version,Editor.displayName,Editor.size);
    }
    catch(e){        
    }
    return null;
}

function Clickheretoprint() {
    var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
    disp_setting += "scrollbars=yes,width=650, height=600, left=100, top=25";
    var content_vlue = document.getElementById("print_content").innerHTML;
    var docprint = window.open("", "", disp_setting);
    docprint.document.open();
    docprint.document.write('<html><head><title>Inel Power System</title>');
    docprint.document.write('</head><body onLoad="self.print()"><center>');
    docprint.document.write(content_vlue);
    docprint.document.write('</center></body></html>');
    docprint.document.close();
    docprint.focus();
}

function splitFile(_url) {
    var _file = "";
    if (_url == null || _url == undefined)
        return [_url, _file];
    var objUrl = _url.split("/");
    var _url = "";
    _file = objUrl[objUrl.length - 1];
    for (var i = 0; i < objUrl.length - 1; i++) {
        _url += (objUrl[i] + "/");
    }
    return [_url, _file];
}

function formatDate(jsDate) {
    var seconds = jsDate.getSeconds() < 10 ? "0" + jsDate.getSeconds() : jsDate.getSeconds();
    var minutes = jsDate.getMinutes() < 10 ? "0" + jsDate.getMinutes() : jsDate.getMinutes();
    var hours = jsDate.getHours() < 10 ? "0" + jsDate.getHours() : jsDate.getHours();
    var day = jsDate.getDate() < 10 ? "0" + jsDate.getDate() : jsDate.getDate();
    var month = jsDate.getMonth() + 1;
    var strMonth = month < 10 ? "0" + month.toString() : month.toString();
    var year = jsDate.getFullYear();
    var strDate = strMonth + "/" + day + "/" + year;
    strDate = strDate + " " + hours + ":" + minutes + ":" + seconds;
    return strDate;
}

//ham su dung de phan trang
function paging(_pages, number_page, flag) {
    $('#pagination').empty();
    if (_pages == 1)
        return;
    //flag = 0 an prev ,1 hien thi ca prev.next, 2 an next
    var bBool = false;
    var strSpan = "<span id=\"prev\" class=\"disabled\">&lt;&lt; Prev</span>";
    if (flag != 0) {
        strSpan = "<a id=\"prev\">&lt;&lt; Prev</a>";
    }
    var className = "class=\"current\"";
    if (_pages <= 10) {
        for (var i = 1; i <= _pages; i++) {
            if (i != number_page) {
                className = "";
                strSpan += "<a id=\"" + i + "\">" + i + "</a>";
            }
            else {
                className = "class=\"current\"";
                strSpan += "<span id=\"" + i + "\" " + className + ">" + i + "</span>";
            }
            bBool = true;
        }
    }
    else if (number_page < _pages - 2) {
        var temp = number_page <= 8 ? 1 : number_page - 7;
        var count = 1;
        while (count <= 8 && count < _pages) {
            if (temp != number_page) {
                className = "";
                strSpan += "<a id=\"" + temp + "\">" + temp + "</a>";
            }
            else {
                className = "class=\"current\"";
                strSpan += "<span id=\"" + temp + "\" " + className + ">" + temp + "</span>";
            }
            temp++;
            count++;
            bBool = true;
        }
        count = _pages - 1;
        strSpan += " ... ";
        while (count <= _pages) {
            if (count != number_page) {
                className = "";
                strSpan += "<a id=\"" + count + "\">" + count + "</a>";
            }
            else {
                className = "class=\"current\"";
                strSpan += "<span id=\"" + count + "\" " + className + ">" + count + "</span>";
            }
            count++;
            bBool = true;
        }
    }
    else if (number_page >= _pages - 2) {
        var temp = number_page - 9;
        strSpan += " ... ";
        while (temp <= _pages) {
            if (temp != number_page) {
                className = "";
                strSpan += "<a id=\"" + temp + "\">" + temp + "</a>";
            }
            else {
                className = "class=\"current\"";
                strSpan += "<span id=\"" + temp + "\" " + className + ">" + temp + "</span>";
            }
            temp++;
            bBool = true;
        }
    }

    var sNext = "<a id=\"next\">&lt;&lt; Next </a>";
    if (flag == 2) {
        sNext = "<span id=\"next\" class=\"disabled\">&lt;&lt; Prev</span>";
    }
    strSpan += sNext;
    if(bBool)
        $('#pagination').append(strSpan);
}

//ham kiem tra chuoi 
function isEmpty(s){
    if(s == "" || s == null || s == undefined){
        return true;
    }
    return false;
}

function isBlank(s){
    for(var i =0;i<s.length;i++){
        var c = s.charAt(i);
        if(c == " " || c != "\n" || c != "\t"){
            return true;
        }
    }
    return false;
}

function equalDateTime(dateFrom,dateTo,character){
    var startDate = parseDate(dateFrom,character).getTime();
    var endDate = parseDate(dateTo,character).getTime();
    if(startDate == endDate){
        return true;
    }
    return false;
}
//ham so sanh 2 ngay
function compare(dateFrom,dateTo,character){
    var startDate = parseDate(dateFrom,character).getTime();
    var endDate = parseDate(dateTo,character).getTime();
    if(startDate > endDate){
        return true;
    }
    return false;
}

//Chuyển chuỗi kí tự (string) sang đối tượng Date()
function parseDate(str,character) {//characters
    var mdy = str.split(character);
    var mm = parseInt(String(mdy[1]),10) - 1;   
    var dd = parseInt(String(mdy[0]),10);
    var yy = parseInt(String(mdy[2]),10);
    return new Date(yy,mm,dd);
}
//ham chi cho phep nhap so
function isNumberKey(e,flag){    
    var charCode = (e.which) ? e.which : window.event.keyCode;    
    if(flag == true){
        if(charCode == 44)
            return true;
    }
    if(charCode > 31 && (charCode < 48 ||charCode > 57)){
        return false;
    }
    return true;
}

function getObjById(id) {
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}

function isExistEmail(email) {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    return emailPattern.test(email);
}

function showElement(id) {
    var myVal = getObjById(id);    
    if (myVal == null || myVal == undefined) {
    }
    else {
        myVal.style.opacity = 1;
    }
}

function hideElement(id) {
    var myVal = getObjById(id);
    if (myVal == null || myVal == undefined) { }
    else {
        myVal.style.opacity = 0;
    }
}
//ham tao the div
function createDiv(className,title){
    var div = document.createElement('div');
    div.className = className;
    if(title != undefined)
        div.innerHTML = title;
    return div;
}
